<template>
  <div>
    <el-menu
        :default-active="activeIndex2"
        active-text-color="#ffd04b"
        background-color="#545c64"
        class="el-menu-demo"
        mode="horizontal"
        text-color="#fff"
        @select="handleSelect">
      <!--      <el-menu-item index="1">进销存管理系统</el-menu-item>-->
      <el-submenu v-show="dataManagement" index="2">
        <template #title>管理</template>
        <el-menu-item v-show="mm" index="2-1">供应商管理</el-menu-item>
        <el-menu-item v-show="cm" index="2-2">客户管理</el-menu-item>
      </el-submenu>
      <el-submenu v-show="purchaseManagement" index="3">
        <template #title>采购管理</template>
        <el-menu-item v-show="pu" index="3-1">采购入库</el-menu-item>
        <el-menu-item v-show="pi" index="3-2">采购信息查询</el-menu-item>
      </el-submenu>
      <el-submenu v-show="checkManagement" index="4">
        <template #title>销售管理</template>
        <el-menu-item v-show="so" index="4-1">销售出库</el-menu-item>
        <el-menu-item v-show="si" index="4-2">销售信息查询</el-menu-item>
      </el-submenu>
      <el-submenu v-show="productManagement" index="5">
        <template #title>库存管理</template>
        <el-menu-item v-show="poi" index="5-1">仓库信息查询</el-menu-item>
      </el-submenu>
      <el-submenu v-show="countManagement" index="6">
        <template #title>统计信息</template>
        <el-menu-item v-show="sco" index="6-1">销售统计</el-menu-item>
        <el-menu-item v-show="cli" index="6-2">客户统计</el-menu-item>
      </el-submenu>
      <el-submenu v-show="powerManagement" index="7">
        <template #title>权限管理</template>
        <el-menu-item v-show="usm" index="7-1">用户管理</el-menu-item>
        <el-menu-item v-show="rom" index="7-2">角色管理</el-menu-item>
      </el-submenu>
      <el-submenu v-show="userManagement" index="8">
        <template #title>个人信息管理</template>
        <el-menu-item v-show="alt" index="8-1">修改密码</el-menu-item>
      </el-submenu>
      <el-submenu v-show="logManagement" index="9">
        <template #title>日志信息</template>
        <el-menu-item v-show="logs" index="9-1">日志一览</el-menu-item>
      </el-submenu>

    </el-menu>
    <el-row>
      <el-col>
        <Supplier v-show="supplier"></Supplier>
        <Client v-show="client"></Client>
        <SaleCount v-show="saleCount"></SaleCount>
        <SaleClient v-show="clientCount"></SaleClient>
        <PurchaseIn v-show="purchaseIn"></PurchaseIn>
        <PurchaseInfo v-show="purchaseInfo"></PurchaseInfo>
        <CheckOut v-show="checkout"></CheckOut>
        <CheckOutInfo v-show="checkInfo"></CheckOutInfo>
        <ProductInfo v-show="productInfo"></ProductInfo>
        <UserManage v-show="userM"></UserManage>
        <RoleManage v-show="roleM"></RoleManage>
        <UpdatePwd v-show="altPassword"></UpdatePwd>
        <LogView v-show="showLog"></LogView>
      </el-col>
    </el-row>
  </div>
</template>

<script>


import Supplier from "../components/Supplier";
import Client from "../components/Client";
import SaleCount from "../components/SaleCount";
import SaleClient from "../components/SaleClient";
import PurchaseIn from "../components/PurchaseIn";
import PurchaseInfo from "../components/PurchaseInfo";
import CheckOut from "../components/CheckOut";
import CheckOutInfo from "../components/CheckOutInfo";
import ProductInfo from "../components/ProductInfo";
import UserManage from "../components/UserManage";
import RoleManage from "../components/RoleManage";
import UpdatePwd from "../components/UpdatePwd";
import LogView from "../components/LogView";

export default {
  name: "Index",
  components: {
    LogView,
    UpdatePwd,
    RoleManage,
    UserManage,
    ProductInfo, CheckOutInfo, CheckOut, PurchaseInfo, PurchaseIn, SaleClient, SaleCount, Client, Supplier
  },
  data() {
    return {
      activeIndex2: '1',
      logoShow: true,

      dataManagement: false,//资料管理模块
      supplier: false, mm: false,//供应商管理子块
      client: false, cm: false,//客户管理子块
      purchaseManagement: false,//采购管理模块
      purchaseIn: false, pu: false//采购入库子模块
      , purchaseInfo: false, pi: false,//采购信息
      checkManagement: false,//销售管理模块
      checkout: false, so: false//销售出库子模块
      , checkInfo: false, si: false,//销售信息
      productManagement: false,//库存管理模块
      productInfo: false, poi: false,
      countManagement: false,//统计信息管理模块
      saleCount: false, sco: false,//销售统计
      clientCount: false, cli: false,//客户统计
      powerManagement: false,//用户权限
      userM: false, usm: false,//用户管理
      roleM: false, rom: false,//用户角色管理
      userManagement: false,//用户自我管理
      altPassword: false, alt: false,//修改密码
      logManagement: false,//日志
      showLog: false, logs: false//日志查询
    }
  }, mounted() {
    this.checkLoginRole()//检查是否有用户进行了登录并将角色生成相应模块
  },
  methods: {
    checkLoginRole() {
      //将存储在全局store中的用户对象取出
      let user = this.$store.state.user
      //如果没有用户则转移至登录界面
      if (user === "" || user == null || user === []) {
        this.$router.push("Login")
      }
      //获得用户的所有角色，进行子主模块显示放行
      let list = user.roleBeanList
      console.log("length=" + list.length)

      //默认生成第一个页面的组件
      let le = list[0].levelBeanList
      this.activeIndex2 = le[0].levelDetail
      this.handleSelect(0, [0, this.activeIndex2])

      //循环获取其角色下的子模块并且将子模块进行生成
      for (let i = 0; i < list.length; i++) {
        // console.log("进入循环")
        let levelList = list[i].levelBeanList
        for (let k = 0; k < levelList.length; k++) {
          //获得子模块的具体描述，可用于对照相应的子主模块进行生成
          let detail = levelList[k].levelDetail
          // console.log(detail)
          if (detail === "2-1") {
            this.mm = true
          }
          if (detail === "2-2") {
            this.cm = true
          }
          if (detail === "3-1") {
            this.pu = true
          }
          if (detail === "3-2") {
            this.pi = true
          }
          if (detail === "4-1") {
            this.so = true
          }
          if (detail === "4-2") {
            this.si = true
          }
          if (detail === "5-1") {
            this.poi = true
          }
          if (detail === "6-1") {
            this.sco = true
          }
          if (detail === "6-2") {
            this.cli = true
          }
          if (detail === "7-1") {
            this.usm = true
          }
          if (detail === "7-2") {
            this.rom = true
          }
          if (detail === "8-1") {
            this.alt = true
          }
          if (detail === "9-1") {
            this.logs = true
          }
        }
      }
      //子模块生成完毕之后，反向生成父模块
      if (this.cm == true || this.mm == true) {
        this.dataManagement = true
      }
      if (this.pu === true || this.pi === true) {
        this.purchaseManagement = true
      }
      if (this.so === true || this.si === true) {
        this.checkManagement = true
      }
      if (this.poi === true) {
        this.productManagement = true
      }
      if (this.sco === true || this.cli === true) {
        this.countManagement = true
      }
      if (this.usm === true || this.rom === true) {
        this.powerManagement = true
      }
      if (this.alt === true) {
        this.userManagement = true
      }
      if (this.logs === true) {
        this.logManagement = true
      }
    },
    handleSelect(key, keyPath) {
      console.log("keyPath=" + keyPath);
      //对所有的子模块首先进行隐藏处理
      this.supplier = false
      this.client = false
      this.purchaseIn = false
      this.purchaseInfo = false
      this.checkout = false
      this.checkInfo = false
      this.saleCount = false
      this.clientCount = false
      this.userM = false
      this.roleM = false
      this.altPassword = false
      this.showLog = false
      this.productInfo = false
      //将选中的子模块进行显示
      if (keyPath[1] === "2-1") {
        this.supplier = true
      }
      if (keyPath[1] === "2-2") {
        this.client = true
      }
      if (keyPath[1] === "3-1") {
        this.purchaseIn = true
      }
      if (keyPath[1] === "3-2") {
        this.purchaseInfo = true
      }
      if (keyPath[1] === "4-1") {
        this.checkout = true
      }
      if (keyPath[1] === "4-2") {
        this.checkInfo = true
      }
      if (keyPath[1] === "5-1") {
        this.productInfo = true
      }
      if (keyPath[1] === "6-1") {
        this.saleCount = true
      }
      if (keyPath[1] === "6-2") {
        this.clientCount = true
      }
      if (keyPath[1] === "7-1") {
        this.userM = true
      }
      if (keyPath[1] === "7-2") {
        this.roleM = true
      }
      if (keyPath[1] === "8-1") {
        this.altPassword = true
      }
      if (keyPath[1] === "9-1") {
        this.showLog = true
      }
    }
  }
}
</script>

<style scoped>

</style>